{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% extends base_template %}

{% block actions %}
    <div class="sonata-actions">
        <ul>
            <li class="sonata-action-element"><a href="{{ admin.generateUrl('create') }}">{% trans "link_action_create" from admin.translationdomain %}</a></li>
            <li class="sonata-action-element"><a href="{{ admin.generateUrl('list') }}">{% trans "link_action_list" from admin.translationdomain %}</a></li>
        </ul>
    </div>
{% endblock %}

{% block side_menu %}{% if side_menu %}{{ side_menu.render|raw }}{% endif %}{% endblock %}

{% block form %}

    {% if object.id > 0 %}
        {% set url = 'edit' %}
    {% else %}
        {% set url = 'create' %}
    {% endif %}

    <form action="{{ admin.generateUrl(url, {'id': object.id, 'uniqid': admin.uniqid}) }}"{% if form.isMultipart %} enctype="multipart/form-data"{% endif %} method="POST">

        {{ form_hidden(form) }}
        
        {% if form.errors %}
            <div class="sonata-ba-form-error">
                {{ form_errors(form) }}
            </div>
        {% endif %}
        
        {% for name, form_group in form_groups %}
            {% if name %}
                <fieldset>
                    <legend>
                        {% trans name %}
                        {% if form_group.collapsed %}
                            <a href="" class="sonata-ba-collapsed">{% trans 'link_expand' from 'AdminBundle' %}</a>
                        {% endif %}
                    </legend>
                    
                    <div class="sonata-ba-collapsed-fields">
            {% endif %}


            {% for field_name in form_group.fields %}
                {% if fields[field_name] is defined %}
                    {{ fields[field_name]|render_form_element(form, object) }}
                {% endif %}
            {% endfor %}

            {% if name %}
                    </div>
                </fieldset>
            {% endif %}
        {% endfor %}

        {% if app.request.isxmlhttprequest %}
            {% if object.id %}
                <input type="submit" name="btn_update" value="{% trans "btn_update" from admin.translationdomain %}"/>
            {% else %}
                <input type="submit" name="btn_create" value="{% trans "btn_create" from admin.translationdomain %}"/>
            {% endif %}
        {% else %}
            {% if object.id %}
                <input type="submit" name="btn_update_and_edit" value="{% trans "btn_update_and_edit_again" from admin.translationdomain %}"/>
                <input type="submit" name="btn_update_and_list" value="{% trans "btn_update_and_return_to_list" from admin.translationdomain %}"/>
            {% else %}
                <input type="submit" name="btn_create_and_edit" value="{% trans "btn_create_and_edit_again" from admin.translationdomain %}"/>
                <input type="submit" name="btn_create_and_create" value="{% trans "btn_create_and_create_a_new_one" from admin.translationdomain %}"/>
            {% endif %}
        {% endif %}
    </form>
{% endblock %}
